<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_banners
 *
 * @copyright   Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

require_once JPATH_ROOT . '/components/com_banners/helpers/banner.php';
$baseurl = JUri::base();
$type 		= $params->get('type',	1);
$catid 		= $params->get('catid',  '');
if($type==0){
?>
<div class="bannergroup<?php echo $moduleclass_sfx ?>">
<?php if ($headerText) : ?>
	<?php echo $headerText; ?>
<?php endif; ?>

<?php foreach ($list as $item) : ?>
	<div class="banneritem">
		<?php $link = JRoute::_('index.php?option=com_banners&task=click&id='. $item->id);?>
		<?php if ($item->type == 1) :?>
			<?php // Text based banners ?>
			<?php echo str_replace(array('{CLICKURL}', '{NAME}'), array($link, $item->name), $item->custombannercode);?>
		<?php else:?>
			<?php $imageurl = $item->params->get('imageurl');?>
			<?php $width = $item->params->get('width');?>
			<?php $height = $item->params->get('height');?>
			<?php if (BannerHelper::isImage($imageurl)) :?>
				<?php // Image based banner ?>
				<?php $alt = $item->params->get('alt');?>
				<?php $alt = $alt ? $alt : $item->name; ?>
				<?php $alt = $alt ? $alt : JText::_('MOD_BANNERS_BANNER'); ?>
				<?php if ($item->clickurl) :?>
					<?php // Wrap the banner in a link?>
					<?php $target = $params->get('target', 1);?>
					<?php if ($target == 1) :?>
						<?php // Open in a new window?>
						<a
							href="<?php echo $link; ?>" target="_blank"
							title="<?php echo htmlspecialchars($item->name, ENT_QUOTES, 'UTF-8');?>">
							<img
								src="<?php echo $baseurl . $imageurl;?>"
								alt="<?php echo $alt;?>"
								<?php if (!empty($width)) echo 'width ="'. $width.'"';?>
								<?php if (!empty($height)) echo 'height ="'. $height.'"';?>
							/>
						</a>
					<?php elseif ($target == 2):?>
						<?php // open in a popup window?>
						<a
							href="<?php echo $link;?>" onclick="window.open(this.href, '',
								'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550');
								return false"
							title="<?php echo htmlspecialchars($item->name, ENT_QUOTES, 'UTF-8');?>">
							<img
								src="<?php echo $baseurl . $imageurl;?>"
								alt="<?php echo $alt;?>"
								<?php if (!empty($width)) echo 'width ="'. $width.'"';?>
								<?php if (!empty($height)) echo 'height ="'. $height.'"';?>
							/>
						</a>
					<?php else :?>
						<?php // open in parent window?>
						<a
							href="<?php echo $link;?>"
							title="<?php echo htmlspecialchars($item->name, ENT_QUOTES, 'UTF-8');?>">
							<img
								src="<?php echo $baseurl . $imageurl;?>"
								alt="<?php echo $alt;?>"
								<?php if (!empty($width)) echo 'width ="'. $width.'"';?>
								<?php if (!empty($height)) echo 'height ="'. $height.'"';?>
							/>
						</a>
					<?php endif;?>
				<?php else :?>
					<?php // Just display the image if no link specified?>
					<img
						src="<?php echo $baseurl . $imageurl;?>"
						alt="<?php echo $alt;?>"
						<?php if (!empty($width)) echo 'width ="'. $width.'"';?>
						<?php if (!empty($height)) echo 'height ="'. $height.'"';?>
					/>
				<?php endif;?>
			<?php elseif (BannerHelper::isFlash($imageurl)) :?>
				<object
					classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
					codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
					<?php if (!empty($width)) echo 'width ="'. $width.'"';?>
					<?php if (!empty($height)) echo 'height ="'. $height.'"';?>
				>
					<param name="movie" value="<?php echo $imageurl;?>" />
					<embed
						src="<?php echo $imageurl;?>"
						loop="false"
						pluginspage="http://www.macromedia.com/go/get/flashplayer"
						type="application/x-shockwave-flash"
						<?php if (!empty($width)) echo 'width ="'. $width.'"';?>
						<?php if (!empty($height)) echo 'height ="'. $height.'"';?>
					/>
				</object>
			<?php endif;?>
		<?php endif;?>
		<div class="clr"></div>
	</div>
<?php endforeach; ?>

<?php if ($footerText) : ?>
	<div class="bannerfooter">
		<?php echo $footerText; ?>
	</div>
<?php endif; ?>
</div>
<?php
}
if($type==1){
?>
	<div id="slider">
    <div class="flexslider">
        <div class="slider-wrap">
        <?php 
		for($i=0;$i<count($list);$i++){
		$item = $list[$i];
		?>
            <div class="slide">
                <img src="<?php echo $item->params->get('imageurl');?>" title="<?php echo $item->name; ?>" alt="<?php echo $item->params->get('alt');?> " />
                <!-- <div class="slide-caption"><?php echo $item->name;?></div> -->
            </div>
		<?php 
		}
		?>
        </div>
    </div>
</div>
<script type="text/javascript">
	jQuery(window).load(function(){
		jQuery(".flexslider").flexslider({
			selector:".slider-wrap > .slide",
			animation:"slide",
			easing:"easeOutExpo",
			direction:"horizontal",
			slideshowSpeed:5000,
			animationSpeed:2000,
			pauseOnAction:true,
			pauseOnHover:true,
			useCSS:true,
			touch:true,
			video:true,
			controlNav:false,
			directionNav:true,
			keyboard:true
		})
	});
</script>
<?php
}
if($type==2){
	$db = & JFactory::getDBO();
	$sql="SELECT * from #__categories where parent_id='".$catid[0]."' and published='1' and level='2'";
	$db->setQuery($sql);
	$lists = $db->loadObjectList();
	if(count($lists)>1){
?>
    <script src="templates/protostar/js/jquery-ui.js"></script>
    <link rel="stylesheet" href="templates/protostar/css/galleriffic-5.css" type="text/css" />
	<script type="text/javascript" src="templates/protostar/js/gallery/jquery.history.js"></script>
    <script type="text/javascript" src="templates/protostar/js/gallery/jquery.galleriffic.js"></script>
    <script type="text/javascript" src="templates/protostar/js/gallery/jquery.opacityrollover.js"></script>
    <script type="text/javascript">
		jQuery(document).ready(function($) {
			$('div.navigationgll').css({'width' : '300px', 'float' : 'left'});
			$('div.content').css('display', 'block');
			$(".each-gallery").each(function(i){
				var onMouseOutOpacity = 0.67;
				$('#thumbs + i + ul.thumbs li').opacityrollover({
					mouseOutOpacity:   onMouseOutOpacity,
					mouseOverOpacity:  1.0,
					fadeSpeed:         'fast',
					exemptionSelector: '.selected'
				});
				var gallery = $('#thumbs'+i).galleriffic({
					delay:                     2500,
					numThumbs:                 5,
					preloadAhead:              10,
					enableTopPager:            true,
					enableBottomPager:         true,
					maxPagesToShow:            7,
					imageContainerSel:         '#slideshow'+ i,
					controlsContainerSel:      '#controls' + i,
					captionContainerSel:       '#caption' + i,
					loadingContainerSel:       '#loading' + i,
					renderSSControls:          true,
					renderNavControls:         true,
					playLinkText:              'Play Slideshow',
					pauseLinkText:             'Pause Slideshow',
					prevLinkText:              '&lsaquo; Previous Photo',
					nextLinkText:              'Next Photo &rsaquo;',
					nextPageLinkText:          'Next &rsaquo;',
					prevPageLinkText:          '&lsaquo; Prev',
					enableHistory:             false,
					autoStart:                 false,
					syncTransitions:           true,
					defaultTransitionDuration: 900,
					onSlideChange:             function(prevIndex, nextIndex) {
							this.find('ul.thumbs').children()
									.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
									.eq(nextIndex).fadeTo('fast', 1.0);
					},
					onPageTransitionOut:       function(callback) {
							this.fadeTo('fast', 0.0, callback);
					},
					onPageTransitionIn:        function() {
							this.fadeTo('fast', 1.0);
					}
				});
			});
		});
	</script>
	<script type="text/javascript">
        jQuery(function() {
            var tabCounter = 2;
            var tabs = jQuery( "#tabs" ).tabs();
            tabs.bind( "keyup", function( event ) {
                if ( event.altKey && event.keyCode === jQuery.ui.keyCode.BACKSPACE ) {
                    var panelId = tabs.find( ".ui-tabs-active" ).remove().attr( "aria-controls" );
                    jQuery( "#" + panelId ).remove();
                    tabs.tabs( "refresh" );
                }
            });
        });
    </script>
    <div class="ui-tabs ui-widget ui-widget-content ui-corner-all pagegallery" id="tabs">
        <ul role="tablist" class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
           	<?php
           	for($i=0;$i<count($lists);$i++){
		  	?>
            <li aria-selected="true" aria-controls="tabs-<?php echo $i;?>" class="ui-state-default ui-corner-top">
                <div class="page_header catroom">
                    <h2><strong><a id="ui-id-<?php echo $i;?>" class="ui-tabs-anchor" href="#tabs-<?php echo $i;?>"><?php echo $lists[$i]->title; ?></a></strong></h2>
                </div>
            </li>
           	<?php
			}
		   	?>
        </ul>
        <?php
		for($i=0;$i<count($lists);$i++){
			$sqlitem="SELECT * from #__banners where catid='".$lists[$i]->id."' and state='1'";
			$db->setQuery($sqlitem);
			$listitems = $db->loadObjectList();
		?>
        <div class="ui-tabs-panel" id="tabs-<?php echo $i;?>">
        	<div class="each-gallery navigation-container">
                <div class="content">
                    <div id="controls" class="controls"></div>
                    <div class="slideshow-container">
                        <div id="loading<?php echo $i;?>" class="loader"></div>
                        <div id="slideshow<?php echo $i;?>" class="slideshow"></div>
                    </div>
                    <div id="caption" class="caption-container"></div>
                </div>
                <div id="thumbs<?php echo $i;?>" class="navigationgll">
                    <ul class="thumbs noscript">
                        <?php
						for($j=0;$j<count($listitems);$j++){
							$imgitem = $listitems[$j];
							$imagegallerypage = $listitems[$j]->params;
							$imagegallerypage = explode('imageurl":"',$imagegallerypage);
							$imagegallerypage = explode('","',$imagegallerypage[1]);
							$imagegallerypage = str_replace('\/','/',$imagegallerypage[0]);
							$altimg = $listitems[$j]->params;
							$altimg = explode('alt":"',$altimg);
							$altimg = explode('"}',$altimg[1]);
							$altimg = $altimg[0];
						?>
                        	<li>
                                <a class="thumb" href="<?php echo $imagegallerypage;?>" title="<?php echo $listitems[$j]->name;?>">
                                    <img class="imggallerypage" src="<?php echo $imagegallerypage;?>" title="<?php echo $listitems[$j]->name;?>" alt="<?php echo $altimg;?>" >
                                </a>
                            </li>
						<?php
						}
						?>
                    </ul>
                </div>
            </div>
        </div>
		<?php
        }
        ?>
    </div>
<?php
	}
}
if($type==3){
	$db = & JFactory::getDBO();
	$sql="SELECT * from #__categories where parent_id='".$catid[0]."' and published='1' and level='2'";
	$db->setQuery($sql);
	$lists = $db->loadObjectList();
	for($i=0;$i<count($lists);$i++){
		$sqlitem="SELECT * from #__banners where catid='".$lists[$i]->id."' and state='1'";
		$db->setQuery($sqlitem);
		$listitems = $db->loadObjectList();
?>
	<div class="page_header catroom gallerytitle">
        <h2><strong><?php echo $lists[$i]->title; ?></strong></h2>
    </div>
<script>
	jQuery(function() {
	  jQuery('#gallerypage<?php echo $i;?>').slidesjs({
		width: 700,
		height: 460
	  });
	});
</script>

<div id="gallerypage<?php echo $i;?>" class="gallerypage">
<?php
for($j=0;$j<count($listitems);$j++){
	$imgitem = $listitems[$j];
	$imagegallerypage = $listitems[$j]->params;
	$imagegallerypage = explode('imageurl":"',$imagegallerypage);
	$imagegallerypage = explode('","',$imagegallerypage[1]);
	$imagegallerypage = str_replace('\/','/',$imagegallerypage[0]);
	$altimg = $listitems[$j]->params;
	$altimg = explode('alt":"',$altimg);
	$altimg = explode('"}',$altimg[1]);
	$altimg = $altimg[0];
?>
	<ul class="galleryarticle<?php echo $listsuites[$i]->id;?>" id="olympGallery">
		<li>
        <a target="_blank" href="<?php echo $imagegallerypage;?>" title="<?php echo $listitems[$j]->name;?>">
            <img class="imggallerypage" src="<?php echo $imagegallerypage;?>" title="<?php echo $listitems[$j]->name;?>" alt="<?php echo $altimg;?>" >
        </a>
        </li>
	</ul>
<?php
}
?>
</div>
<?php
	}
}
?>